package zqservlet;

import net.sf.json.JSONObject;
import zqdb.O_INFO;
import zqtools.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet(name = "comServlet",urlPatterns = "/com")
public class comServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        O_INFO of = new O_INFO();

        Enumeration<String> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String s = parameterNames.nextElement();
            switch (s) {
                case "URL":
                    of.setURL(request.getParameter(s));
                    break;
                case "CMD":
                    of.setCMD(request.getParameter(s));
                    break;
                case "VALUE01":
                    of.setVALUE01(request.getParameter(s));
                    break;
                case "VALUE02":
                    of.setVALUE02(request.getParameter(s));
                    break;
                case "VALUE03":
                    of.setVALUE03(request.getParameter(s));
                    break;
                case "VALUE04":
                    of.setVALUE04(request.getParameter(s));
                    break;
                case "VALUE05":
                    of.setVALUE05(request.getParameter(s));
                    break;
                case "VALUE06":
                    of.setVALUE06(request.getParameter(s));
                    break;
                case "VALUE07":
                    of.setVALUE07(request.getParameter(s));
                    break;
                case "VALUE08":
                    of.setVALUE08(request.getParameter(s));
                    break;
                case "VALUE09":
                    of.setVALUE09(request.getParameter(s));
                    break;
                case "VALUE10":
                    of.setVALUE10(request.getParameter(s));
                    break;
                case "VALUE11":
                    of.setVALUE11(request.getParameter(s));
                    break;
                case "VALUE12":
                    of.setVALUE12(request.getParameter(s));
                    break;
                case "VALUE13":
                    of.setVALUE13(request.getParameter(s));
                    break;
                case "VALUE14":
                    of.setVALUE14(request.getParameter(s));
                    break;
                case "VALUE15":
                    of.setVALUE15(request.getParameter(s));
                    break;
                case "VALUE16":
                    of.setVALUE16(request.getParameter(s));
                    break;
                case "VALUE17":
                    of.setVALUE17(request.getParameter(s));
                    break;
                case "VALUE18":
                    of.setVALUE18(request.getParameter(s));
                    break;
                case "VALUE19":
                    of.setVALUE19(request.getParameter(s));
                    break;
                case "VALUE20":
                    of.setVALUE20(request.getParameter(s));
                    break;
                case "PIC1":
                    of.setPIC1(request.getParameter(s));
                    break;
                case "PIC2":
                    of.setPIC2(request.getParameter(s));
                    break;
                case "PIC3":
                    of.setPIC3(request.getParameter(s));
                    break;
                case "PIC4":
                    of.setPIC4(request.getParameter(s));
                    break;
                case "PIC5":
                    of.setPIC5(request.getParameter(s));
                    break;
                case "PIC6":
                    of.setPIC6(request.getParameter(s));
                    break;
                case "PIC7":
                    of.setPIC7(request.getParameter(s));
                    break;
                case "PIC8":
                    of.setPIC8(request.getParameter(s));
                    break;
                case "PIC9":
                    of.setPIC9(request.getParameter(s));
                    break;
                default:
                    break;
            }
        }

        JSONObject j = DBUtil.f_query(of);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().print(j);
        j.clear();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
